package com.keepsoft.util;

import com.keepsoft.core.entity.PictureFile;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;

public class ReadPng {

    public static void main(String[] args) {
//        getFiles("C:\\Users\\Administrator\\Desktop\\201712");
        String name="123131313.txt";
        System.out.println(name.substring(0,name.lastIndexOf(".")));
    }

    /**
     * 读取某个目录下所有文件、文件夹
     * @param path
     * @return LinkedHashMap<String,String>
     */
    public static  ArrayList<PictureFile> getFiles(String path) {
        ArrayList<PictureFile> arrayList=new ArrayList();
        File file = new File(path);
        File[] tempList = file.listFiles();

        for (int i = 0; i < tempList.length; i++) {
            if(tempList[i].isFile()){
                PictureFile pictureFile=new PictureFile();
                pictureFile.setFILE_NAME(tempList[i].getName());
                String id=tempList[i].getName().substring(0,tempList[i].getName().lastIndexOf("."));
                pictureFile.setFILE_CD(id);
                pictureFile.setFILE_SIZE(getFileSizeByLength(tempList[i].length()));
                pictureFile.setFILE_PATH("HB/WrPm/Img/201712/"+tempList[i].getName());
                arrayList.add(pictureFile);
            }
        }
        return arrayList;
    }

    public static String getFileSizeByLength(double length){
        return String.format("%.1f",length/1024.0);
    }
}
